package tests;

public class Printer {
	static boolean on = true;
	
	public static void set(boolean b){
		 on = b;
	}
	//printing stuffs
	static int tabcount = 0;
	public static void tab(){
		tabcount ++;
	}
	public static void untab(){
		tabcount --;
		if( tabcount <0){
			tabcount = 0;
		}
	}
	
	public static void resettab(){
		tabcount=0;
	}
	
	public static void println(){
		if( !on) return;
		System.out.println();
		System.out.flush();
	}
	public static void println(Object...o){
		if( !on) return;
		print(o);
		System.out.println();
		System.out.flush();
	}
	
	public static void print(Object... o){
		if( !on) return;
		if( o==null) return;
		//print tabs
		for(int i = 0; i<tabcount; i++){
			System.out.print("\t");
		}
		for(int i = 0; i<o.length;i++){
			if( o[i] instanceof Object[]){
				printArr((Object[])o[i]);
			}
			else
				System.out.print(o[i].toString());
		}
		System.out.flush();
	}
	
	public static void printArr(Object[] o){
		if( !on) return;
		if( o==null) return;
		System.out.print("{");
		for(int i = 0; i<o.length-1;i++){
				System.out.print(o[i].toString()+", ");
		}
		System.out.print(o[o.length-1].toString()+"}");
		System.out.flush();
	}
	
	public static void errprintln(Object...o){
		if( !on) return;
		errprint(o);
		System.err.println();
		System.err.flush();
	}
	
	public static void errprint(Object... o){
		if( !on) return;
		if( o==null) return;
		//print tabs
		for(int i = 0; i<tabcount; i++){
			System.err.print("\t");
		}
		for(int i = 0; i<o.length;i++){
			if( o[i] instanceof Object[]){
				printArr((Object[])o[i]);
			}
			else
				System.err.print(o[i].toString());
		}
		System.err.flush();
	}
}
